package com.springboot.cropsboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springboot.cropsboot.entity.Admin;
import com.springboot.cropsboot.entity.Nongzw;
import com.springboot.cropsboot.entity.Pici;
import com.springboot.cropsboot.mapper.PiciMapper;
import com.springboot.cropsboot.qpage.QPage;
import com.springboot.cropsboot.service.IPiciService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.springboot.cropsboot.util.ResultView;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author admin
 * @since 2023-12-02
 */
@Service
public class PiciServiceImpl extends ServiceImpl<PiciMapper, Pici> implements IPiciService {


    @Override
    public ResultView getPageList(QPage qPage, Pici obj) {
        QueryWrapper<Pici> queryWrapper=new QueryWrapper<>();
        if(!StringUtils.isEmpty(obj.getPname())){
            queryWrapper.like("pname",obj.getPname());
        }
        IPage iPage = new Page(qPage.getOffset(), qPage.getLimit());
        IPage<Pici> mapList = this.page(iPage,queryWrapper);
        return ResultView.ok(mapList);
    }

    @Override
    public ResultView saveObj(Pici obj) {
        boolean count=this.save(obj);
        if(!count){
            return ResultView.error("数据异常，操作失败");
        }
        return ResultView.ok();
    }

    @Override
    public ResultView updateObj(Pici obj) {
        boolean count=this.updateById(obj);
        if(!count){
            return ResultView.error("数据异常，操作失败");
        }
        return ResultView.ok();
    }

    @Override
    public ResultView deleteObj(Pici obj) {
        boolean count=this.removeById(obj.getId());
        if(!count){
            return ResultView.error("数据异常，操作失败");
        }
        return ResultView.ok();
    }

}
